/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.fpt.practice.utility;

import java.awt.Desktop;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

/**
 *
 * @author Administrator
 */
public class Utility {
    
    /**
     * Open file on desktop support
     * @param file 
     */
    public static void openFiles(String file){
        try {

            File pdfFile = new File(file);
            if (pdfFile.exists()) {

                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().open(pdfFile);
                } else {
                    //System.err.println("Awt Desktop is not supported!");
                }

            } else {
                //System.err.println("File is not exists!");
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /**
     * Tạo file lấy thông số connect database oracle
     * write thông tin config       
     * @param file_ora
     * @return getConnORA
     */
    public static String getConfigORA(String file_ora) throws IOException {

        String getConnORA = "";
        File file = new File(file_ora);
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        DataInputStream dis = null;
        String line = null;
        try {

            //Create file 
            if (!file.exists()) {
                file.createNewFile();
                //write use buffering
                Writer output = new BufferedWriter(new FileWriter(file));
                output.write("jdbc:oracle:thin:@10.15.117.98:1522/DPPIT,TKTQ,TKTQ");
                output.close();
            }

            fis = new FileInputStream(file);

            // Here BufferedInputStream is added for fast reading.
            bis = new BufferedInputStream(fis);
            dis = new DataInputStream(bis);

            // dis.available() returns 0 if the file does not have more lines.
            while ((line = dis.readLine()) != null) {
                getConnORA = line;
            }

            // dispose all the resources after using them.
            fis.close();
            bis.close();
            dis.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return getConnORA;
    }

    
}
